<div class="dialog">
    <table>
        <tbody>
        
            <tr class="prop">
                <td valign="top" class="name">
                    <label for="serialNumber"><g:message code="distribution.serialNumber" default="Serial Number" />:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: distributionInstance, field: 'serialNumber', 'errors')}">
                    <g:textField name="serialNumber" maxlength="11" value="${fieldValue(bean: distributionInstance, field: 'serialNumber')}" />
                </td>
        
                <td valign="top" class="name">
                    <label for="retailer"><g:message code="distribution.retailer" default="Retailer" />:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: distributionInstance, field: 'retailer', 'errors')}">
                    <g:textField name="retailerInput" value="${distributionInstance?.retailer?.encodeAsHTML()}"/>
                    <g:hiddenField name="retailer.id" value="${distributionInstance?.retailer?.id}" />
                 </td>
        
                <td valign="top" class="name">
                    <label for="date"><g:message code="distribution.date" default="Date" />:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: distributionInstance, field: 'date', 'errors')}">
                    <g:jqDatePicker name="date" value="${distributionInstance?.date}"></g:jqDatePicker>
                </td>
            </tr>
        
            <tr class="prop">
                <td valign="top" class="name">
                    <label for="maker"><g:message code="distribution.maker" default="Maker" />:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: distributionInstance, field: 'maker', 'errors')}">
                    <g:textField name="makerInput" value="${distributionInstance?.maker?.encodeAsHTML()}"/>
                    <g:hiddenField name="maker.id" value="${distributionInstance?.maker?.id}" />
                 </td>
        
                <td valign="top" class="name">
                    <label for="driver"><g:message code="distribution.driver" default="Driver" />:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: distributionInstance, field: 'driver', 'errors')}">
                    <g:textField name="driverInput" value="${distributionInstance?.driver?.encodeAsHTML()}"/>
                    <g:hiddenField name="driver.id" value="${distributionInstance?.driver?.id}" />
                </td>
                                
                <td valign="top" class="name">
                    &nbsp;
                </td>
                <td valign="top" class="value">
                    &nbsp;
                </td>
 
            </tr>
               
        </tbody>
    </table>
    <g:hiddenField name="approved" value="${distributionInstance?.approved}" />
</div>
<!--detail-->
<div class="list">
    <table>
        <thead>
            <tr>
                <th><g:message code="distributionDetail.serialNumber" default="Serial Number" /></th>
                <th><g:message code="distributionDetail.product" default="Product" /></th>
                <th><g:message code="distributionDetail.unit" default="Unit" /></th>
                <th class="number"><g:message code="distributionDetail.quantity" default="Quantity" /></th>
                <th class="number"><g:message code="distributionDetail.sended" default="Sended" /></th>
                <th class="number"><g:message code="distributionDetail.price" default="Price" /></th>
                <th class="number"><g:message code="distributionDetail.retailPrice" default="Retail Price" /></th>
                <th class="number"><g:message code="distributionDetail.amount" default="Amount" /></th>
                <th class="number"><g:message code="distributionDetail.retailAmount" default="Retail Amount" /></th>
                <th><g:message code="distributionDetail.packages" default="Packages" /></th>
                <th class="number"><g:message code="distributionDetail.packageUsed" default="Package Used" /></th>
                <th class="number"><g:message code="distributionDetail.packageReturned" default="Package Returned" /></th>
            </tr>
        </thead>
        <tbody>
        <g:each in="${distributionInstance?.details?.sort{it?.serialNumber}}" status="i" var="distributionDetailInstance">
            <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                <!--serialNumber-->
                <td>
                    ${fieldValue(bean: distributionDetailInstance, field: "serialNumber")}
                    <g:hiddenField name="details[${i}].serialNumber" value="${distributionDetailInstance?.serialNumber}" />
                </td>
                <!--product-->
                <td>
                    ${fieldValue(bean: distributionDetailInstance, field: "product")}
                    <g:hiddenField name="details[${i}].product.id" value="${distributionDetailInstance?.product?.id}" />
                </td>
                <!--unit-->
                <td>
                    ${fieldValue(bean: distributionDetailInstance, field: "unit")}
                    <g:hiddenField name="details[${i}].unit" value="${distributionDetailInstance?.unit}" />
                </td>
                <!--quantity-->
                <td class="number">
                    <g:textField name="details[${i}].quantity" value="${distributionDetailInstance?.quantity}"/>
                </td>
                <!--sended-->
                <td class="number">
                    ${formatNumber(number : distributionDetailInstance?.sended ?: 0, format : '###,##0.00')}
                    <g:hiddenField name="details[${i}].sended" value="${formatNumber(number : distributionDetailInstance?.sended ?: 0, format : '###,##0.00')}"/>
                </td>
                <!--price-->
                <td class="number">
                    <g:textField name="details[${i}].price" value="${formatNumber(number : distributionDetailInstance?.price ?: 0, format : '###,##0.00')}"/>
                </td>
                <!--retailPrice-->
                <td class="number">
                    ${formatNumber(number : distributionDetailInstance?.retailPrice ?: 0, format : '###,##0.00')}
                    <g:hiddenField name="details[${i}].retailPrice" value="${formatNumber(number : distributionDetailInstance?.retailPrice ?: 0, format : '###,##0.00')}"/>
                </td>
                <!--amount-->
                <td class="number">
                    ${formatNumber(number : distributionDetailInstance?.amount ?: 0, format : '###,##0.00')}
                    <g:hiddenField name="details[${i}].amount" value="${formatNumber(number : distributionDetailInstance?.amount ?: 0, format : '###,##0.00')}"/>
                </td>
                <!--retailAmount-->
                <td class="number">
                    ${formatNumber(number : distributionDetailInstance?.retailAmount ?: 0, format : '###,##0.00')}
                    <g:hiddenField name="details[${i}].retailAmount" value="${formatNumber(number : distributionDetailInstance?.retailAmount ?: 0, format : '###,##0.00')}"/>
                </td>
                <!--packages-->
                <td>
                    <g:textField name="details[${i}].packagesInput" value="${distributionDetailInstance?.packages?.encodeAsHTML()}"/>
                    <g:hiddenField name="details[${i}].packages.id" value="${distributionDetailInstance?.packages?.id}" />
                </td>
                <!--packageUsed-->
                <td class="number">
                    <g:textField name="details[${i}].packageUsed" value="${formatNumber(number : distributionDetailInstance?.packageUsed ?: 0, format : '###,##0.00')}"/>
                </td>
                <!--packageReturned-->
                <td class="number">
                    ${formatNumber(number : distributionDetailInstance?.packageReturned ?: 0, format : '###,##0.00')}
                    <g:hiddenField name="details[${i}].packageReturned" value="${formatNumber(number : distributionDetailInstance?.packageReturned ?: 0, format : '###,##0.00')}"/>
                </td>
            </tr>
        </g:each>
        </tbody>
    </table>
</div>

